package com.sysmanagment.model;

import java.util.GregorianCalendar;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Version;

@MappedSuperclass
public class SgtEntity  {
	
	private Integer id;

	private GregorianCalendar createdOn;

	private GregorianCalendar lastUpdatedOn;

	private GregorianCalendar lastAccessOn;
	
	private Integer version;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public GregorianCalendar getCreatedOn() {
		return createdOn;
	}

	public void setCreatedOn(GregorianCalendar createdOn) {
		this.createdOn = createdOn;
	}

	public GregorianCalendar getLastUpdatedOn() {
		return lastUpdatedOn;
	}

	public void setLastUpdatedOn(GregorianCalendar lastUpdatedOn) {
		this.lastUpdatedOn = lastUpdatedOn;
	}

	public GregorianCalendar getLastAccessOn() {
		return lastAccessOn;
	}

	public void setLastAccessOn(GregorianCalendar lastAccessOn) {
		this.lastAccessOn = lastAccessOn;
	}

	
	@Version
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	@PrePersist
	public void prePersist(){
		setCreatedOn((GregorianCalendar) GregorianCalendar.getInstance());
		setLastUpdatedOn((GregorianCalendar) GregorianCalendar.getInstance());
	}

	@PreUpdate
	public void preUpdate(){
		setLastUpdatedOn((GregorianCalendar) GregorianCalendar.getInstance());
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SgtEntity other = (SgtEntity) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
	
}
